package pers.xhh.frontapi.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import pers.xhh.frontapi.annotation.UserLoginToken;
import pers.xhh.frontapi.common.Mi;
import pers.xhh.frontapi.entity.to.receiver.MiReceiverPutTo;
import pers.xhh.frontapi.entity.to.receiver.MiReceiverTo;
import pers.xhh.frontapi.service.MiReceiverService;

/**
 * 地址
 * @author wei-xhh
 * @date 2020-12-08
 */
@CrossOrigin
@RestController
@RequestMapping("/mi/api")
public class ReceiverController {

    @Autowired
    MiReceiverService miReceiverService;

    @UserLoginToken
    @PostMapping("/receiver")
    public Mi addReceiver(@RequestBody MiReceiverTo miReceiverTo) {
        return miReceiverService.addReceiver(miReceiverTo);
    }

    @UserLoginToken
    @PostMapping("/receiver/{receiverId}")
    public Mi updateReceiver(@RequestBody(required = false) MiReceiverPutTo miReceiverTo,
                             @PathVariable("receiverId") Integer receiverId) {
        return miReceiverService.updateReceiver(receiverId, miReceiverTo);
    }

    @UserLoginToken
    @DeleteMapping("/receiver/{receiverId}")
    public Mi deleteReceiver(@PathVariable("receiverId") Integer receiverId) {
        return miReceiverService.deleteReceiver(receiverId);
    }

    @UserLoginToken
    @GetMapping("/receiver/all")
    public Mi getAllReceiver() {
        return miReceiverService.getAllReceiver();
    }

}
